# set: 无序，可变，唯一
# 定义 {e1, e2, ...} / set(e1, e2, ...)
# 空set = set(), 区分空字典{}

parts = { 'spring', 'maven', 'openjdk', 'intellij', 'maven', 'h2' }
print(parts) # {'maven', 'spring', 'intellij', 'h2', 'openjdk'}

if 'h2' in parts:
    print('h2在的噢')
else:
    print('h2不存在的')

# set可以进行集合运算
a = set('abracadabra')
b = set('alacazam')

# {'a', 'r', 'c', 'b', 'd'}
print(a)

#     print(a + b)
#           ~~^~~
# TypeError: unsupported operand type(s) for +: 'set' and 'set'
# print(a + b)
print(a - b) # 差集(a有，b无)
print(a | b) # 并集
print(a & b) # 交集
print(a ^ b) # 互不存在的
'''
{'d', 'r', 'b'}
{'c', 'r', 'b', 'd', 'z', 'l', 'a', 'm'}
{'c', 'a'}
{'l', 'r', 'b', 'd', 'z', 'm'}
'''

#    c = { 1, [], a, b}
#        ^^^^^^^^^^^^^^
# TypeError: unhashable type: 'list'
# c = { 1, [], a, b}
# print(c)